<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Tasks - Fuel Documentation</title>
	<link href="../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../assets/js/nav.js"></script>
	<script type="text/javascript" src="../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('general', '../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>Fuel Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2>Tasks</h2>

		<h3>What is a task?</h3>

		<p>Tasks are classes that can be run through the command line or set up as a cron job. They are generally used for background processes, timed tasks and maintenance tasks. Tasks can calls models and other classes just like controllers.</p>

		<h3>Creating a task</h3>

		<p>In Fuel Controllers are put in the <kbd>fuel/app/tasks</kbd> directory. Below is an example of the task "example": </p>

<pre class="php"><code>namespace Fuel\Tasks;

class Example {

	public function run($message = 'Hello!')
	{
		echo $message;
	}
}</code></pre>

		<p>That will be called via the refine utility within oil:</p>
		
		<pre class="cli">$ php oil refine example "Good morning"</pre>.

		<p>When just the name of the task is used in the command, the method <kbd>"run()"</kbd> is referenced.</p>

		<h4 id="more_methods">Splitting tasks into more methods</h4>

		<p>You can add more methods to your task class to break a group of tasks down into more specific tasks which can be called separately.</p>

<pre class="php"><code>public function current_date()
{
	echo date('Y-m-d');
}</code></pre>

		<p>We can then call this method using:</p>
		
		<pre class="cli">$ php oil refine example:current_date</pre>

	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>